package com.central.utils.es

import com.alibaba.fastjson.{JSON, JSONObject}
import org.apache.http.HttpHost
import org.elasticsearch.action.bulk.BulkRequest
import org.elasticsearch.action.index.IndexRequest
import org.elasticsearch.client.{RequestOptions, RestClient, RestHighLevelClient}

import scala.util.parsing.json.JSONObject

object ESMethod {

  val client = new RestHighLevelClient(RestClient.builder(new HttpHost("192.168.5.180", 9200, "http"), new HttpHost("192.168.5.180", 9201, "http")))


  def InsertData(indexName: String,typeName:String,strings: Array[java.util.HashMap[String,Object]])= {

    val requests = new BulkRequest()
    for (i<- 0 to strings.length-1) {
      requests.add(new IndexRequest(indexName, typeName).source(strings(i)))
    }
    client.bulk(requests, RequestOptions.DEFAULT)

  }

}
